Skip to content

resolve main class automatically#71

Merged
ansyral merged 5 commits into
microsoft:masterfrom
ansyral:resolvemainclass
Oct 18, 2017
Merged

resolve main class automatically#71
ansyral merged 5 commits into
microsoft:masterfrom
ansyral:resolvemainclass

Conversation

@ansyral

@ansyral ansyral commented Oct 11, 2017

Copy link
Copy Markdown
Contributor

Signed-off-by: xuzho <xuzho@microsoft.com>
List<String> projectNames;
if (arguments.size() > 1 && arguments.get(1) != null) {
// project name specified
projectNames = new ArrayList<String>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ArrayList<> is better

projects.add(rootElm.elementText("name"));
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add log like logger.error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see examples:#68

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document is not closed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't see any close/dispose method for Reader/document

e.printStackTrace();
}
}
projects.add(null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while add null here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fall back to workspace scope

IJavaSearchScope searchScope = createSearchScope(projectName);
SearchPattern pattern = SearchPattern.createPattern("main(String[]) void", IJavaSearchConstants.METHOD,
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_EXACT_MATCH);
ArrayList<String> uris = new ArrayList<String>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<String> uris = new ArrayList<>()

Signed-off-by: xuzho <xuzho@microsoft.com>
private List<String> resolveProjectName(List<String> projectFiles) {
List<String> projects = new ArrayList<>();
for (String f : projectFiles) {
SAXReader reader = new SAXReader();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does eclipse have any built-in utility to help parse .project file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems not

SearchEngine searchEngine = new SearchEngine();
searchEngine.search(pattern, new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
searchScope, requestor, null /* progress monitor */);
return uris.size() == 0 ? null : uris.get(0);

@testforstephen testforstephen Oct 12, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there are multiple main class in the target project, should pop up a dropdown menu in UI to tell user to choose one.[#Pending]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should return multiple to let js side has the possibilities to choose.

andxu
andxu previously approved these changes Oct 12, 2017
@microsoft microsoft deleted a comment from msftclas Oct 15, 2017
Signed-off-by: xuzho <xuzho@microsoft.com>
}
if (o instanceof ResolutionItem) {
ResolutionItem item = (ResolutionItem) o;
return item.mainClass == this.mainClass && item.projectName == this.projectName;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in java == is not for equal test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, i should use equals instead

if (project != null) {
String mainClass = method.getDeclaringType().getFullyQualifiedName();
String projectName = ProjectsManager.DEFAULT_PROJECT_NAME.equals(project.getName()) ? null : project.getName();
uris.add(new ResolutionItem(mainClass, projectName));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename a reasonable name.

* @return main class and project name
* resolve main class and project name.
* @return an array of main class and project name
* @throws CoreException when there are error when resolving main class.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors


@Override
public int hashCode() {
return mainClass.hashCode() * 13 + (projectName == null ? 0 : projectName.hashCode());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing the handle case for null mainClass and null projectName

IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
SearchPattern pattern = SearchPattern.createPattern("main(String[]) void", IJavaSearchConstants.METHOD,
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_EXACT_MATCH);
ArrayList<ResolutionItem> uris = new ArrayList<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uris -> results

Signed-off-by: xuzho <xuzho@microsoft.com>
andxu
andxu previously approved these changes Oct 18, 2017
Signed-off-by: xuzho <xuzho@microsoft.com>
return resolveMainClassCore();
}

private List<ResolutionItem> resolveMainClassCore() throws CoreException {

@testforstephen testforstephen Oct 18, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new method resolveMainClassCore is unnecessary.[pending]

@ansyral
ansyral merged commit 6158bf2 into microsoft:master Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants